﻿/*                              
   Copyright 2011 Nils Kopal, Christopher Krüger, Simone Sauer, Dennis Nolte, Uni Duisburg-Essen

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sharebert.LinkLayerLibrary
{

    /// <summary>
    /// Message type used to ping a host. May contain a listen port, which is used to tell 
    /// the bootstrap server the listen port of the peer.
    /// </summary>
    [Serializable]
    public class Ping
    {
        public Ping()
        {
        }

        public Ping(int port)
        {
            this.ListenPort = port;
        }

        public int ListenPort { get; set; }
    }

    /// <summary>
    /// Message type used to tell the host that we are going offline. May contain a listen 
    /// port, which is used by the bootstrap server to identify the specific peer.
    /// </summary>
    [Serializable]
    public class Offline
    {
        public Offline()
        {
        }

        public Offline(int port)
        {
            this.ListenPort = port;
        }

        public int ListenPort { get; set; }
    }

    /// <summary>
    /// This message is used by the client to ask the bootstrap server for the specified number of active peers.
    /// </summary>
    [Serializable]
    public class PeerListRequest
    {
        public PeerListRequest()
        {
        }

        public PeerListRequest(int port, int n)
        {
            this.ListenPort = port;
            this.PeerCount = n;
        }

        public int ListenPort { get; set; }
        public int PeerCount { get; set; }        
    }

    /// <summary>
    /// A list of peer entries.
    /// This class is used by the bootstrap server to send a list of currently active peers to a new peer.
    /// </summary>
    [Serializable]
    public class PeerList
    {
        public PeerList()
        {
        }

        public PeerList(PeerEntry[] peers, string ip)
        {
            this.Peers = peers;
            this.IpAdress = ip;
        }

        public PeerEntry[] Peers { get; set; }
        public string IpAdress { get; set; }
    }

    /// <summary>
    /// Represents a single peer. Contains IP address and port number and the last time the server heard from him
    /// </summary>
    [Serializable]
    public class PeerEntry
    {
        public PeerEntry()
        {
        }

        public PeerEntry(string ip, int port)
        {
            this.IP = ip;
            this.Port = port;
        }

        public string IP;

        public int Port;

        public DateTime LastPingTime { get; set; }
    }

}
